﻿using ConfExpert.Forms.Base;

using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo.Westbrook
{
    public partial class Styles : XForm
    {
        public Styles()
        {
            InitializeComponent();
        }

        BindingSource bsStyle;
        DateTime LastUpdate = new DateTime(2000, 1, 1);
        private void Styles_Load(object sender, EventArgs e)
        {
            
            TAM.StyleTableAdapter = new Datasets.MyDataTableAdapters.StyleTableAdapter();
            GetDetails("Style", "GetStyles", LastUpdate);
            if (ds.Style.Rows.Count > 0)
            {
                LastUpdate = ((DateTime)ds.Style.Compute("MAX(ModifiedOn)", string.Empty));
            }

            bsStyle = new BindingSource(ds, "Style");

            InitGridView(gvStyles, bsStyle);
            AddBsToList(bsStyle);

            if (ytk(132))
            {
                GridManager gm = GridManager.GetManager(gvStyles);
                gm.GridMenu.AddMenu("EN-TR Çeviri", EN_TR_Click);
            }


            DataTable dtModelTipi = new DataTable();
            dtModelTipi.Columns.Add("Name", typeof(string));
            dtModelTipi.Columns.Add("Value", typeof(decimal));
            dtModelTipi.Rows.Add("Erkek Uzun", 1.7);
            dtModelTipi.Rows.Add("Erkek Kısa", 1.5);
            dtModelTipi.Rows.Add("Erkek Büyük Beden", 2);
            dtModelTipi.Rows.Add("Bayan Uzun", 1.3);
            dtModelTipi.Rows.Add("Bayan Kısa", 1.1);
            dtModelTipi.Rows.Add("Çocuk", 1);
            RepositoryItemGridLookUpEdit riGumruk = GetCustomGLE(dtModelTipi, "Name", "Value");
            gvStyles.Columns["ModelTipi"].ColumnEdit = riGumruk;


            gvStyles.Columns["COStyleId"].Visible = false;
            gvStyles.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;

            gvStyles.SetFilterTypeToCheckedList("Style");
            btnSave.ItemClick += btnSave_ItemClick;
            gvStyles.BestFitColumns();
        }

        void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
            GetDetails("Style", "GetStyles", LastUpdate);
        }

        private string GetIdx()
        {
            string idxs = "";
            foreach (int rowHandle in gvStyles.GetSelectedRows())
                if (rowHandle > -1)
                    idxs += gvStyles.GetRowCellValue(rowHandle, "StyleId").ToString() + ",";

            idxs = idxs.RemoveIfEndsWith(",");

            return idxs;
        }

        private void EN_TR_Click(object sender, EventArgs e)
        {
            string idxs = string.Empty;
            idxs = GetIdx();

            DataTable dtTranslate = ExecuteDataTable("WBtranslateSelectedStyle", idxs);
            if (dtTranslate.Rows.Count > 0)
            {
                using (Ref rf = new Ref(dtTranslate))
                    rf.ShowDialog();
            }
        }
    }
}